<?php
header("Content-Type: text/plain; charset=UTF-8");
$keyword = $_GET['keywords'];
if(!$keyword)exit();
class DBSQL
{
	private $CONN = "";
	
	public function __construct(){
		try{
			$conn = mysql_connect('localhost','root','root');
		}catch(exception $e){
			$msg = $e;
		}
		try{
			mysql_query("SET NAMES utf8");
		}catch(exception $e){
			$msg = $e;
		}
		try{
			mysql_select_db('blog',$conn);
		}catch(exception $e){
			$msg = $e;
		}
		$this->CONN = $conn;
	}
	
	public function select($sql=""){
		if(empty($sql)) return false;
		if(empty($this->CONN)) return false;
		try{
			$results = mysql_query($sql,$this->CONN);
		}catch(exception $e){
			$msg = $e;
		}
		if((!$results) || (empty($results))){
			@mysql_free_result($results);
			return false;
		}
		$count = 0;
		$data = array();

		while($row = @mysql_fetch_array($results)){
			$data[$count]= $row;
			$count++;
		}

		@mysql_free_result($results);

		return $data;
	}
}
class Blog extends DBSQL
{
	public function __construct(){
		parent::__construct();
	}
	
	public function GetPostTitle($blogid, $keyword = ''){
		$sql = "SELECT F_POSTS_TITLE FROM ee_blog_posts WHERE F_ID_USER_INFO = $blogid";
		if($keyword) $sql .= " AND F_POSTS_TITLE like '%$keyword%'";
		return $this->select($sql);
	}
	
	public function GetCatList($blogid, $name, $cat1FID=0)
	{
		$sql = "SELECT * FROM $name c WHERE F_ID_BLOG_INFO = $blogid";
		if($cat1FID > 0)
			$sql .= " AND c.F_ID_CATEGORIES1 = $cat1FID";
//		$sql .= " ORDER BY F_ID DESC";
		return $this->select($sql);
	}
}
//echo $keyword;
$blog = new Blog();
$results = $blog->GetPostTitle(1,$keyword);
$results2 = array();
foreach($results as $re){
	array_push($results2, $re['F_POSTS_TITLE']);
}
echo json_encode($results2);
?>